package com.wyd.jwpkglxt_ssm.util;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.HashMap;
import java.util.Map;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResultUtil {
    private Boolean success;
    private Integer code;
    private String msg;
    private Map<String,Object> data = new HashMap<>();
    //public static ResultUtil of(ResultCode resultCode){
    //    return new ResultUtil(resultCode.getCode(),resultCode.getMsg());
    //}

    public ResultUtil(Boolean success,Integer code,String msg){
        this.success = success;
        this.code = code;
        this.msg = msg;
    }

    public static ResultUtil ok(){
        return new ResultUtil(true,ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMsg());
    }

    public static ResultUtil error(ResultCode resultCode){
        return new ResultUtil(false,resultCode.getCode(),resultCode.getMsg());
    }

    public ResultUtil data(Map<String,Object> data){
        this.data = data;
        return this;
    }

    public ResultUtil data(String key,Object value){
        this.data.put(key, value);
        return this;
    }


}
